package tugas.akhir.jason;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;



public class dr0_mainmenuassessor extends Activity{
	Button dr0_logout,dr0_mulai,dr0_edit;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dr0_assessormainmenu);
        
        dr0_mulai = (Button) findViewById(R.id.dr0_mulai);
        dr0_logout = (Button) findViewById(R.id.dr0_logout);
        
        dr0_mulai.setOnClickListener(new View.OnClickListener() {
    		public void onClick(View view)
    		{
    			 try {
                     File sd = Environment.getExternalStorageDirectory();
                     File data = Environment.getDataDirectory();

                     if (sd.canWrite()) {
                         String currentDBPath = "//data//"+ "tugas.akhir.jason" +"//databases//"+"middas.sqlite";
                         String backupDBPath = "middas.sqlite";
                         File currentDB = new File(data, currentDBPath);
                         File backupDB = new File(sd, backupDBPath);

                             FileChannel src = new FileInputStream(currentDB).getChannel();
                             FileChannel dst = new FileOutputStream(backupDB).getChannel();
                             dst.transferFrom(src, 0, src.size());
                             src.close();
                             dst.close();
                             Toast.makeText(getBaseContext(), backupDB.toString(), Toast.LENGTH_LONG).show();

                     }
                 } catch (Exception e) {

                     //Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();


                 }

    		
    		
    		{ Intent intent = new Intent();
    	    intent.setAction(Intent.ACTION_PICK);
    	    // FTP URL (Starts with ftp://, sftp:// or ftps:// followed by hostname and port).
    	    //Uri ftpUri = Uri.parse("ftp://192.168.0.104:21");
    	    Uri ftpUri = Uri.parse("ftp://192.168.0.101:21");
    	    intent.setDataAndType(ftpUri, "vnd.android.cursor.dir/lysesoft.andftp.uri");
    	    // FTP credentials (optional)
    	    intent.putExtra("ftp_username", "anonymous");
//    	    intent.putExtra("ftp_password", "");
//    	    intent.putExtra("ftp_keyfile", "/sdcard/dsakey.txt");
//    	    intent.putExtra("ftp_keypass", "optionalkeypassword");
    	    // FTP settings (optional)
//    	    intent.putExtra("ftp_pasv", "true");
//    	    intent.putExtra("ftp_resume", "true");
//    	    intent.putExtra("ftp_encoding", "UTF8");
    	    // Upload
    	    intent.putExtra("command_type", "upload");
    	    // Activity title
    	    intent.putExtra("progress_title", "Uploading files MIDDAS...");
    	    intent.putExtra("local_file1", "/sdcard/middas.sqlite");
    	    //intent.putExtra("local_file2", "/sdcard/CartoonCamera/");
    	    // Optional initial remote folder (it must exist before upload)
    	    intent.putExtra("remote_folder", "/incoming");
    	    startActivityForResult(intent, 1);  }
    		}
    		//{ startActivity(new Intent(dr0_mainmenuassessor.this, laporan.class)); }
    	});
        
//        dr0_edit.setOnClickListener(new View.OnClickListener() {
//    		public void onClick(View view)
//    		  { startActivity(new Intent(dr0_mainmenuassessor.this, dr0_editassessor.class)); }
//    	});
        
        dr0_logout.setOnClickListener(new View.OnClickListener() {
      		public void onClick(View view) {  			
      		// TODO Auto-generated method stub
                AlertDialog.Builder alertKeluar = new AlertDialog.Builder(dr0_mainmenuassessor.this);
                alertKeluar.setMessage("Anda yakin logout dan kembali ke HOME?")
                .setCancelable(false)	//Button jika cancel
    	        .setPositiveButton("YA", new AlertDialog.OnClickListener(){  //Button jika ya
                   public void onClick(DialogInterface arg0, int arg1) {
                      // TODO Auto-generated method stub
                	   startActivity(new Intent(dr0_mainmenuassessor.this, MIDDASActivity.class)); }
                })
                .setNegativeButton("TIDAK",new AlertDialog.OnClickListener(){ //Jika memilih Tidak
                   public void onClick(DialogInterface dialog, int which) {
                      // TODO Auto-generated method stub
                      dialog.cancel();   
                   }   
                });
                AlertDialog a = alertKeluar.create();
                a.setTitle("Home");
                a.setIcon(R.drawable.middasicon);
                a.show();
             } 
        });
          
    }
}
    